package org.cug.service.impl;

import org.cug.mapper.ForeignclassMapper;
import org.cug.mapper.UserMapper;
import org.cug.pojo.ForeignClass;
import org.cug.pojo.User;
import org.cug.service.ForeignclassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ForeignclassServiceimpl implements ForeignclassService {
    @Autowired
    private ForeignclassMapper foreignclassMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<ForeignClass> list (Integer userId, Integer semester) {
        User user =userMapper.getrole(userId);
        List<Integer> ids=new ArrayList<>();
        if(user.getRole().equals("1")){
            ids.add(userId);
        }
        else if(user.getRole().equals("2")){
            ids = userMapper.getusers(user.getDepartment());
        }else if(user.getRole().equals("3")){
            ids = userMapper.getuserscol(user.getCollege());
        }else {
            List<ForeignClass> foreignclasses=foreignclassMapper.listall(semester);
            return foreignclasses;
        }
        List<ForeignClass> foreignclasses=foreignclassMapper.list(ids,semester);
        return foreignclasses;
    }

    @Override
    public void add(ForeignClass foreignclass) {
        foreignclassMapper.insert(foreignclass);
    }

    @Override
    public void delete(List<Integer> ids) {
        foreignclassMapper.delete(ids);
    }

    @Override
    public ForeignClass selectid(Integer id) {
        return foreignclassMapper.selectid(id);
    }

    @Override
    public void alterbyid(ForeignClass foreignclass) {
        foreignclassMapper.update(foreignclass);
    }
}
